package cn.sytton.taffecloud.serivce.auth.security.pwd;

import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import javax.annotation.Resource;

/**
 * 用户密码AuthenticationProvider
 *
 * @author skyrock
 */
@Component
public class UserPwdAuthenticationProvider extends DaoAuthenticationProvider {

    @Resource
    private UserDetailsService userPwdDetailsService;

    @Override
    protected void doAfterPropertiesSet() {
        Assert.notNull(this.userPwdDetailsService, "A userPwdDetailsService must be set");
        setUserDetailsService(userPwdDetailsService);
        setPasswordEncoder(new BCryptPasswordEncoder());
    }
}
